package org.bringer.webapp.services.impl;

import org.apache.tapestry5.ValueEncoder;
import org.bringer.model.Account;
import org.bringer.service.AccountManager;


public class AccountEncoder implements ValueEncoder<Account> {

    private AccountManager accountManager;

    public AccountEncoder(AccountManager accountManager) {
        this.accountManager = accountManager;
    }

    public String toClient(Account value) {
        return value != null ? String.valueOf(value.getIbanCode()) : null;
    }

    public Account toValue(String ibanCode) {

        if (ibanCode == null || "null".equals(ibanCode)) {
            return null;
        }
        Account account = accountManager.getAccountByIban(ibanCode);
     

        return account;
    }

}
